package com.sensetime.bi.senselink.server.parse;

import com.sensetime.bi.senselink.server.entity.rtp.TcpRtpPacket;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RtpEncoder extends MessageToByteEncoder<TcpRtpPacket> {
    @Override
    protected void encode(ChannelHandlerContext ctx, TcpRtpPacket msg, ByteBuf out) {
        if (msg.tcpHeader != null) {
            log.debug("send message,type=[{}],body=[{}]", msg.tcpHeader.channel, msg.tcpHeader.rtpPkgLength);
            out.writeByte(msg.tcpHeader.magic);
            out.writeByte(msg.tcpHeader.channel);
            out.writeShort(msg.tcpHeader.rtpPkgLength);
        }
        out.writeBytes(msg.getRtpBytes());
    }
}